@extends('admin.common.base-master')

@section('html-head')
    <link href="{{url('css/admin/pagenum.css')}}" rel="stylesheet" />

@endsection

@section('html-body')
    <div id="content">
        <!-- cur-position start -->
        <div id="cur-position">
            <span class="tit">当前位置：</span>
            <a href="#">书籍管理</a>
            <em></em>
            <a href="#">文字书籍列表</a>
        </div>

        <div class="filter-box clearfix">

            <div class="fr">
                <a class="addBtn" href="{{route("Admin.Home.booksWordSet")}}">新增</a>
            </div>
        </div>
        <div class="table-box">
            <table class="table">
                <thead>
                <tr>
                    <th>ID</th>
                    <th>书籍名称</th>
                    <th>书籍封面</th>
                    <th>书籍作者</th>
                    <th>书籍类型</th>
                    <th>是否完结</th>
                    <th>是否推荐</th>
                    <th>是否新书精选</th>
                    <th>阅读币价格</th>
                    <th>书籍分类</th>
                    <th>状态</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                @if(count($booksWords) > 0)
                    @foreach($booksWords as $booksWord)
                        <tr id="book_{{$booksWord->id}}">
                            <td>{{$booksWord->id}}</td>
                            <td>{{$booksWord->name}}</td>
                            <td class="account-td" style="width: 5%;">
                        <span class="photo" style="border-radius: 100%;display:initial">
                            @if($booksWord->img_id !== 0)
                                <a href="javascript:void(0);" class="openimg" data-key="{{$booksWord->img_id}}"><img src="{{$booksWord->img_url}}" alt=""></a>
                            @else
                                <img src="{{url('images/default-avatar.png')}}" alt="">
                            @endif
                        </span>
                            </td>
                            <td>{{$booksWord->author}}</td>
                            <td>
                                @if($booksWord->type == 'word')
                                    文字
                                @else
                                    音频
                                @endif
                            </td>
                            <td>
                                @if($booksWord->is_complete == 0)
                                    <p style="color: red;">连载中</p>
                                @else
                                    <p style="color: green;">完结</p>
                                @endif
                            </td>
                            <td>
                                @if($booksWord->home_show == 0)
                                    <p style="color: red;">不推荐</p>
                                @else
                                    <p style="color: green;">推荐</p>
                                @endif
                            </td>
                            <td>
                                @if($booksWord->is_featured == 0)
                                    <p style="color: red;">否</p>
                                @else
                                    <p style="color: green;">是</p>
                                @endif
                            </td>
                            <td>{{$booksWord->books_coin_price}}</td>
                            <td>@if($booksWord->classify_id!==0)
                                    {{$booksWord->classify_name}}
                                @endif</td>
                            <td>
                                @if($booksWord->status == 0)
                                    <p style="color: red;">下架</p>
                                @else
                                    <p style="color: green;">上架</p>
                                @endif
                            </td>
                            <td style="overflow: visible;">
                                <a class="color2" href="{{route("Admin.Home.booksWordSet")}}?id={{$booksWord->id}}">编辑</a><span>|</span>
                                <a class="color2" href="{{route("Admin.Home.booksChapterList")}}?books_info_id={{$booksWord->id}}">章节设置</a><span>|</span>
                                <a href="javascript:void(0);" class="del" data-id="{{$booksWord->id}}">删除 </a>
                            </td>
                        </tr>
                    @endforeach
                @endif
                </tbody>
            </table>
        </div>
        <div class="pagelist" style="text-align: center;">
            <?php echo $booksWords->render(); ?>
        </div>
    </div>
    <script>
        $(function(){

            $(document).on("click",".del",function(){
                var id = $(this).attr("data-id");
                $.ajax({
                    url:'{{route("Api.Admin.sys.delBooksWord")}}',
                    type:'post',
                    dataType:'json',
                    data:{id:id},
                    success:function(obj){
                        if(obj.level == "success"){
                            $("#book_"+id).hide('slow');
                        }else{
                            noty({type:obj.level,text:obj.message,timeout:600});
                        }
                    },
                    error:function(obj){
                        console.log(obj);
                    }

                });
            });
        });
    </script>
@endsection